// exportToPdf.ts
import jsPDF from 'jspdf';
import html2canvas from 'html2canvas';

export const exportTableToPdf = async (
  element: HTMLElement,
  fileName: string,
  orientation: 'portrait' | 'landscape' = 'portrait'
) => {
  const canvas = await html2canvas(element);
  const imgData = canvas.toDataURL('image/png');
  const pdf = new jsPDF(orientation, 'mm', 'a4');
  const imgProps = pdf.getImageProperties(imgData);
  const pdfWidth = pdf.internal.pageSize.getWidth();
  const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;

  pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
  pdf.save(fileName);
};